package com.ruoyi.service.account.enums.labor;

import cn.hutool.json.JSONUtil;
import com.ruoyi.service.account.enums.IOFlagEnum;
import com.ruoyi.service.account.model.labor.RewardModel;
import com.ruoyi.service.account.model.labor.SalaryModel;
import lombok.Getter;

/**
 * <p>
 * 作用：变动类型
 * </p>
 *
 * @author Zane
 * @since 2025-10-05 21:15
 */
@Getter
public enum LaborAccountChangeTypeEnum {
  XZ("XZ", "薪资", IOFlagEnum.IN, "项目薪资", SalaryModel.class),
  JL("JL", "奖励", IOFlagEnum.IN, "平台奖励", RewardModel.class),
  CF("CF", "处罚", IOFlagEnum.OUT, "平台处罚", RewardModel.class),
  TX("TX", "提现", IOFlagEnum.OUT, "员工提现", RewardModel.class),
  ;
  /**
   * 编码
   */
  private final String code;

  /**
   * 输入输出标识  锁定 0 ,入账 1, 出账 -1
   */
  private final IOFlagEnum ioFlag;
  /**
   * 名称
   */
  private final String name;
  /**
   * 描述
   */
  private final String desc;
  /**
   * 模型
   */
  private final Class<?> cls;

  LaborAccountChangeTypeEnum(String code, String name, IOFlagEnum ioFlag, String desc,
      Class<?> cls) {
    this.code = code;
    this.name = name;
    this.ioFlag = ioFlag;
    this.desc = desc;
    this.cls = cls;
  }

  public boolean eqCode(String code) {
    return this.code.equals(code);
  }

  public static LaborAccountChangeTypeEnum valueOfCode(String changeType) {
    for (LaborAccountChangeTypeEnum value : LaborAccountChangeTypeEnum.values()) {
      if (value.eqCode(changeType)) {
        return value;
      }
    }
    throw new IllegalArgumentException("变动类型不存在");
  }

  @SuppressWarnings("unchecked")
  public <T> T getCls(String value) {
    return (T) JSONUtil.toBean(value, cls);
  }

  public static void main(String[] args) {
    final SalaryModel salaryModel = LaborAccountChangeTypeEnum.XZ.getCls(
        "{\"projectId\":\"1\",\"projectName\":\"1\",\"postName\":\"1\",\"postLevel\":\"1\"}");
    System.out.println(salaryModel.getProjectName());
  }
}
